<template>
  <div class="app-container">
    <div class="qrCodeContainer" style="width: 450px; height: 50px; display: none; width: 100%">
      <h1 class="title" style="width: 480px; margin-left: 27%">{{ companyId === 'HF' ? $t(`Print.RongCangGarmentCoLtdCnsumablesWarehousingList`) : $t(`Print.RongyangGarmentCoLtdCnsumablesWarehousingList`) }}</h1>
      <div style="width: 95%; margin: auto">
        <div style="display: flex; width: 100%; font-size: 13px; justify-content: space-between">
          <h2 style="margin-left: 70px; font-size: 13px">{{ $t(`Print.InboundOrderNumber`) }}:{{ slipNoList3[0]?.slipNo }}</h2>
          <h2 style="margin-left: 70px; font-size: 13px">{{ $t(`Print.StorageDate`) }}:{{ slipNoList3[0]?.slipDate }}</h2>
          <h2 style="margin-left: 70px; font-size: 13px">{{ $t(`Print.Manufacturers`) }}:{{ slipNoList3[0]?.vendorName }}</h2>
          <h2 style="margin-left: 70px; font-size: 13px">{{ $t(`Print.WarehousingReason`) }}:{{ slipNoList3[0]?.slipReason }}</h2>
          <h2 style="margin-left: 70px; font-size: 13px">{{ $t(`Print.TabulatedDate`) }}:{{ formatCurrentDateTime(currentDate) }}</h2>
        </div>

        <div style="width: 100%">
          <table style="width: 100%; font-size: 13px">
            <thead>
              <tr>
                <th>{{ $t(`Print.Department`) }}</th>
                <th>{{ $t(`Print.MaterialColorKey`) }}</th>
                <th>{{ $t(`Print.MaterialName`) }}</th>
                <th>{{ $t(`Print.Specification`) }}</th>
                <th>{{ $t(`Print.Unit`) }}</th>
                <th>{{ $t(`Print.Quantity`) }}</th>
                <th>{{ $t(`Print.UnitPrice`) }}</th>
                <th>{{ $t(`Print.Amount`) }}</th>
                <th>{{ $t(`Print.Remark`) }}</th>
              </tr>
            </thead>
            <tbody>
              <tr v-for="(iten1, index) in slipNoList3" :key="index">
                <td>{{ iten1.deptName }}</td>

                <td>{{ iten1.mtlColor }}</td>
                <td>{{ iten1.mtlName }}</td>
                <td>{{ iten1.mtlSpec }}</td>
                <td>{{ iten1.mtlUnit }}</td>

                <td>{{ iten1.qty }}</td>

                <td>{{ iten1.price }}</td>
                <td>{{ iten1.amt }}</td>

                <td>{{ iten1.remark }}</td>
                <!-- 更多的数据单元格 -->
              </tr>
              <!-- 更多的行 -->
            </tbody>
            <!-- 可选的 tfoot 部分 -->
          </table>

          <!-- <Table :tableHeader="tableHeader5" :tableData="slipNoList" /> -->
        </div>

        <div style="display: flex; justify-content: space-between; width: 85%; font-size: 17px; width: 80%; margin: auto">
          <h2 style="font-size: 13px">{{ $t(`Print.SupplyAndMarketingSupervisor`) }}:</h2>
          <h2 style="font-size: 13px">{{ $t(`Print.Purchaser`) }}:{{ userInfo?.chiName }}</h2>
          <h2 style="font-size: 13px">{{ $t(`Print.WarehouseKeeper`) }}:{{ userInfo?.chiName }}</h2>
        </div>
      </div>
    </div>

    <Find :OriginalFilter="{ static: true }" :formList="formList5" @findClicked="findData" @Launchform="Launchform5" />
    <Find :OriginalFilter="{ static: true }" :searchImg="false" :formList="formList1" @findClicked="findData6" @Launchform="Launchform3" />

    <el-card style="margin-top: 10px" shadow="always" :body-style="{ padding: '5px' }">
      <h1>{{ $t(`Print.DetailsPendingForStorage`) }} <span style="color: red; font-size: 13px">{{ $t(`Print.TheQuantityIsNotEmptyBeforeTheOutboundBatchIsProcessed`) }}</span></h1>
      <Table
        :isLoading="isLoading"
        @confirmChange="confirmChange1"
        @currentRow="currentRow"
        :tableHeader="tableHeader"
        :tableData="QueryDetailsToBeStoredMethodsTableDateList"
        :TableHeight="50"
        :outTableHeight="80"
      />
      <h1>{{ $t(`Print.WarehousingDetails`) }}</h1>
      <Table
        @currentRow="currentRow2"
        :isLoading="isLoading2"
        :tableHeader="tableHeader1"
        :tableData="QueryTheStorageDetailsMethodsTableDateList"
        :TableHeight="50"
        :outTableHeight="80"
      />
      <PageModule :PageData="{ total: total1 }" @pageSizeChange="handleSizeChangeTk1" @pageChange="handleCurrentChangeTk1" />
    </el-card>

    <!-- 指令材料 -->
    <el-drawer v-model="drawer3" :direction="'ttb'" size="small" :with-header="false">
      <Find :OriginalFilter="{ static: true }" :searchImg="false" :formList="formList2" @Launchform="Launchform2" @findClicked="findData1" />
      <div style="width: 60%; margin-top: 13px">
        <Table
          :isLoading="isLoading1"
          @currentRow1="currentRowList1"
          @currentRow="currentRowList"
          :tableHeader="tableHeader2"
          :tableData="SelectMaterialQueryMehtodsTableDateList.dtos"
          :TableHeight="40"
          :outTableHeight="70"
        />
        <PageModule :PageData="{ total }" @pageSizeChange="handleSizeChangeTk" @pageChange="handleCurrentChangeTk" />
      </div>

      <h1 style="margin-top: 15px">物料资料建档</h1>
      <Find :OriginalFilter="{ static: true }" :searchImg="false" :formList="formList3" @Launchform="Launchform1" @findClicked="findData5" />
    </el-drawer>
  </div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import LoginWork from '@/utils/LoginWork'
import JMessage from '@/utils/JMessage'
export default defineComponent({
  name: 'ConsumablesIn'
})
</script>
<script lang="ts" setup>
import { i18n, Jzhcn } from '@/i18n'
import { ref, onMounted } from 'vue'
import {
  StorageDetailsAdded,
  ToBeDeleted,
  SelectMaterialNew,
  GeneratedMaterialCoding,
  MaterialDeletion,
  DetailsToBeStoredAreAdded,
  SelectMaterialQuery,
  GainClassification,
  GainVendor,
  GainDeptNmae,
  QueryTheStorageDetails,
  QueryDetailsToBeStored,
  deleteRow
} from '@/api/WarehouseDepartment/FactoryStorage/ConsumablesIn'
import type {
  StorageDetailsAddedParms,
  SelectMaterialNewPamrs,
  SelectMaterialQueryInterface,
  QueryTheStorageDetailsParms
} from '@/api/WarehouseDepartment/FactoryStorage/ConsumablesIn'
import { ElMessage } from 'element-plus'
import { ElMessageBox } from 'element-plus'
const isLoading = ref(false)
const isLoading2 = ref(false)

const slipNoList3 = ref<any>([])

// 入库删除
const deleteRowParms = ref({
  mtlNo: '',
  slipNo: ''
})

const handleCloseMateriaLKlcList1 = (_done?: () => void) => {
  ElMessageBox.confirm('确定要删除该数据吗')
    .then(async () => {
      deleteRowMethods()
    })
    .catch(() => {})
}

const deleteRowMethods = async () => {
  try {
    const result = await deleteRow(deleteRowParms.value.mtlNo, deleteRowParms.value.slipNo)
    if (result.code === 200) {
      QueryTheStorageDetailsMethods()
      deleteRowParms.value = {
        mtlNo: '',
        slipNo: ''
      }
      JMessage.success(result.message)
    } else {
      JMessage.error(result.message)
    }
  } catch (error) {
    JMessage.error('删除失败')
  }
}

const printQRCode = () => {
  const qrCodeContainer = document.querySelector<any>('.qrCodeContainer')
  if (qrCodeContainer) {
    // 临时显示 .qrCodeContainer 以获取其内容
    qrCodeContainer.style.display = 'block'

    const printWindow = window.open('', '_blank')
    printWindow!.document.write(`
      <!DOCTYPE html>
      <html>
        <head>
          <title>打印指令领料作业</title>
          <link rel="stylesheet" type="text/css" href="print.css" media="print">
          <style>
            body, html {
              margin: 0;
              padding: 0;
            }
            @page {
              size: auto; 
              margin: 3mm;
            }
            @media print {
                /* 打印时的样式 */
             
                
                /* 其他打印样式 */
            }
            h2 {
                    margin-left: initial; /* 或者设置适合打印的左边距 */
                    page-break-inside: avoid; /* 避免在h2元素内部分页 */
                }
               

            table, th, td {
                    border: 1px solid black; 
                    border-collapse: collapse; 
                    text-align: center;
                  }
                  th, td {
                    padding: 5px; /* 设置内边距 */
                    text-align: left; /* 设置文本对齐方式 */
                    text-align: center;
                    font-size:11px
                  }
                  .double-line {
                    border-top: 2px dashed red; 
                    border-bottom: 2px dashed red; 
                    text-align: center;
                  }
           
            /* 可以在这里添加更多自定义的打印样式 */
          </style>
        </head>
        <body>
    `)

    // 将 .qrCodeContainer 的内容复制到打印窗口的 body 中
    const cloneContainer = qrCodeContainer.cloneNode(true)
    printWindow!.document.body.appendChild(cloneContainer)

    printWindow!.document.write(`
        </body>
      </html>
    `)
    printWindow!.document.close()

    // 开始打印
    printWindow!.print()

    // 打印完成后，可以恢复 .qrCodeContainer 的原始显示状态
    qrCodeContainer.style.display = 'none'
  }
}

const currentRow2 = (row: any) => {
  slipNoList3.value = QueryTheStorageDetailsMethodsTableDateList.value.filter((item: any) => row.slipNo === item.slipNo)
  deleteRowParms.value.mtlNo = row.mtlNo
  deleteRowParms.value.slipNo = row.slipNo
}

const formList1 = ref([
  {
    type: 'input',
    inputPlaceholder: '入库单号',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '入库原因',
    selectLabel: '',
    selectOptions: [
      {
        optionKey: 1,
        optionValue: '材料入库',
        optionLabel: '材料入库'
      },
      {
        optionKey: 2,
        optionValue: '盘盈调整',
        optionLabel: '盘盈调整'
      },
      {
        optionKey: 3,
        optionValue: '现金入库',
        optionLabel: '现金入库'
      }
    ]
  },
  {
    type: 'input',
    inputPlaceholder: '送货单号',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '厂商',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'input',
    inputPlaceholder: '材料名称',
    inputValue: ''
  },
  {
    type: 'date',
    dateLabel: '入库日期',
    dateValue: ''
  },
  {
    type: 'date',
    dateLabel: '送货日期',
    dateValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '待入库明细删除'
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '入库明细删除',
    bgColor: '#1890FF'
  }
])

const formList2 = ref([
  {
    type: 'select',
    selectValue: '',
    selectP: '分类',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'input',
    inputPlaceholder: '材料名称',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '删除'
  }
])

const formList3 = ref([
  {
    type: 'input',
    inputPlaceholder: '物料编号',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '品名',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '单位',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '分类',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'input',
    inputPlaceholder: '规格',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '颜色',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '清空'
  },
  {
    type: 'button',
    checkboxLabel: '生成物料编码'
  },
  {
    type: 'button',
    checkboxLabel: '增加'
  }
])

const formList5 = ref([
  {
    type: 'button',
    checkboxLabel: '选择材料'
  },
  {
    type: 'dateSingle',
    dateLabel: '入库日期',
    dateValue: '',
    disabled: true
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '入库原因',
    selectLabel: '',
    selectOptions: [
      {
        optionKey: 1,
        optionValue: '材料入库',
        optionLabel: '材料入库'
      },
      {
        optionKey: 2,
        optionValue: '盘盈调整',
        optionLabel: '盘盈调整'
      },
      {
        optionKey: 3,
        optionValue: '现金入库',
        optionLabel: '现金入库'
      }
    ]
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '部门',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '厂商',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'dateSingle',
    dateLabel: '送货日期',
    dateValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入送货单号',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '入库批处理'
  },
  {
    type: 'button',
    checkboxLabel: '打印'
  }
])

const findData6 = (count: string) => {
  if (count === '待入库明细删除') {
    if (ToBeDeletedParmsMtlNo.value === '') {
      JMessage.warning('请选择需要删除的数据')
    } else {
      handleCloseMateriaLKlcList()
    }
  }
  if (count === '入库明细删除') {
    if (deleteRowParms.value.mtlNo === '' || deleteRowParms.value.slipNo === '') {
      JMessage.warning('请选择需要删除的数据')
    } else {
      handleCloseMateriaLKlcList1()
    }
  }
  if (count === '置空') {
    clearFormList3()
  }
}

const clearFormList3 = () => {
  formList1.value.forEach((item) => {
    if (item.type === 'input') {
      item.inputValue = ''
    }
    if (item.type === 'select') {
      item.selectValue = ''
    }
    if (item.type === 'date') {
      item.dateValue = ''
    }
  })

  formList5.value.forEach((item) => {
    if (item.type === 'input') {
      item.inputValue = ''
    }
    if (item.type === 'select') {
      item.selectValue = ''
    }
    if (item.type === 'date') {
      item.dateValue = ''
    }
    if (item.type === 'dateSingle') {
      item.dateValue = ''
    }
  })
}
// 待入剩料明细修改
const confirmChange1 = async (row: any) => {
  row.remark === null ? (row.remark = '') : row.remark
  row.qty = row.qty === null ? 0 : row.qty
  const result = await LoginWork.post<any, any>(`/pcFactorStockQuery/csmInTempUpdate?mtlNo=${row.mtlNo}&qty=${row.qty}&remark=${row.remark}`)
  if (result.code === 200) {
    QueryDetailsToBeStoredMethods()
    JMessage.success(result.message)
  } else {
    QueryDetailsToBeStoredMethods()
    JMessage.error(result.message)
  }
}

// 日期
const formatCurrentDateTime = (date?: Date) => {
  const year = date!.getFullYear()
  const month = String(date!.getMonth() + 1).padStart(2, '0') // 使用padStart确保月份是两位数
  const day = String(date!.getDate()).padStart(2, '0') // 使用padStart确保日期是两位数
  const hours = String(date!.getHours()).padStart(2, '0') // 小时
  const minutes = String(date!.getMinutes()).padStart(2, '0') // 分钟
  const seconds = String(date!.getSeconds()).padStart(2, '0') // 秒

  // 返回格式化的日期时间字符串
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
}

// 日期
const formatCurrentDateTime1 = (date?: Date) => {
  const year = date!.getFullYear()
  const month = String(date!.getMonth() + 1).padStart(2, '0') // 使用padStart确保月份是两位数
  const day = String(date!.getDate()).padStart(2, '0') // 使用padStart确保日期是两位数

  // 返回格式化的日期时间字符串
  return `${year}-${month}-${day}`
}

const currentDate = ref<any>(new Date())

// 入库明细资料新增
const Launchform5 = (row: any) => {
  StorageDetailsAddedMethodsParms.value.slipDate = formatCurrentDateTime1(currentDate.value)
  StorageDetailsAddedMethodsParms.value.slipReason = row[2].selectValue
  StorageDetailsAddedMethodsParms.value.deptNo = row[3].selectValue.split(' ')[0]
  StorageDetailsAddedMethodsParms.value.deptName = row[3].selectValue.split(' ')[1]
  StorageDetailsAddedMethodsParms.value.vendorName = row[4].selectValue.split(' ')[1]
  StorageDetailsAddedMethodsParms.value.vendorNo = row[4].selectValue.split(' ')[0]
  StorageDetailsAddedMethodsParms.value.sysDate = row[5].dateValue
  StorageDetailsAddedMethodsParms.value.sendNo = row[6].inputValue
}

const StorageDetailsAddedMethodsParms = ref<StorageDetailsAddedParms>({
  deptName: '',
  deptNo: '',
  mtlNo: '',
  sendNo: '',
  slipDate: '',
  slipReason: '',
  sysDate: '',
  vendorName: '',
  vendorNo: ''
})

const StorageDetailsAddedMethods = async () => {
  const result = await StorageDetailsAdded(StorageDetailsAddedMethodsParms.value)
  if (result.code === 200) {
    QueryDetailsToBeStoredMethods()
    QueryTheStorageDetailsMethods()
    JMessage.success(result.message)
  } else {
    QueryDetailsToBeStoredMethods()
    QueryTheStorageDetailsMethods()
    JMessage.error(result.message)
  }
}

// 待出剩料删除
const currentRow = (row: any) => {
  const { mtlNo } = row
  ToBeDeletedParmsMtlNo.value = mtlNo
  StorageDetailsAddedMethodsParms.value.mtlNo = mtlNo
}

const ToBeDeletedParmsMtlNo = ref('')

const ToBeDeletedMethods = async () => {
  const result = await ToBeDeleted(ToBeDeletedParmsMtlNo.value)
  if (result.code === 200) {
    ToBeDeletedParmsMtlNo.value = ''
    QueryDetailsToBeStoredMethods()
    JMessage.success(result.message)
  } else {
    QueryDetailsToBeStoredMethods()
    JMessage.error(result.message)
  }
}

const handleCloseMateriaLKlcList = (_done?: () => void) => {
  ElMessageBox.confirm('确定要删除该数据吗')
    .then(async () => {
      ToBeDeletedMethods()
    })
    .catch(() => {})
}

// 选择材料新增
const SelectMaterialNewMehtodsParms = ref<SelectMaterialNewPamrs>({
  mtlColor: '',
  mtlName: '',
  mtlNo: '',
  mtlSpec: '',
  mtlUnit: '',
  typeName: '',
  typeNo: ''
})

const SelectMaterialNewMehtods = async () => {
  const result = await SelectMaterialNew(SelectMaterialNewMehtodsParms.value)
  if (result.code === 200) {
    SelectMaterialQueryMehtods()
    JMessage.success(result.message)
  } else {
    SelectMaterialQueryMehtods()
    JMessage.error(result.message)
  }
}

// 生成物料编码
const clearFormList1 = () => {
  formList3.value.forEach((item) => {
    if (item.type === 'input') {
      item.inputValue = ''
    }
    if (item.type === 'select') {
      item.selectValue = ''
    }
  })
}

const mtlTypeList = ref('')

const findData5 = (count: string) => {
  if (count === '生成物料编码') {
    GeneratedMaterialCodingMethods()
  }
  if (count === '清空') {
    clearFormList1()
  }
  if (count === '增加') {
    if (
      SelectMaterialNewMehtodsParms.value.mtlName === '' ||
      SelectMaterialNewMehtodsParms.value.mtlNo === '' ||
      SelectMaterialNewMehtodsParms.value.mtlColor === ''
    ) {
      JMessage.warning('物料编号物料名称颜色不可为空')
    } else {
      SelectMaterialNewMehtods()
    }
  }
}

const Launchform1 = (row: any) => {
  SelectMaterialNewMehtodsParms.value.mtlNo = row[0].inputValue
  SelectMaterialNewMehtodsParms.value.mtlName = row[1].inputValue
  SelectMaterialNewMehtodsParms.value.mtlUnit = row[2].inputValue

  SelectMaterialNewMehtodsParms.value.typeNo = row[3].selectValue.split(' ')[0]
  SelectMaterialNewMehtodsParms.value.mtlSpec = row[4].inputValue
  SelectMaterialNewMehtodsParms.value.mtlColor = row[5].inputValue
  SelectMaterialNewMehtodsParms.value.typeName = row[3].selectValue.split(' ')[1]
  mtlTypeList.value = row[3].selectValue.split(' ')[0]
}

const GeneratedMaterialCodingMethods = async () => {
  if (mtlTypeList.value === '') {
    JMessage.warning('请选择分类在进行生成')
  } else {
    const result = await GeneratedMaterialCoding(mtlTypeList.value)
    if (result.code === 200) {
      formList3.value[0].inputValue = result.data
      JMessage.success('写入成功')
    } else {
      JMessage.error('写入失败')
    }
  }
}

// 选择材料删除
const currentRowList = (row: any) => {
  MaterialDeletionMethodsParms.value = row.mtlNo
}

const MaterialDeletionMethodsParms = ref('')

const MaterialDeletionMethods = async () => {
  const result = await MaterialDeletion(MaterialDeletionMethodsParms.value)
  if (result.code === 200) {
    SelectMaterialQueryMehtods()
    MaterialDeletionMethodsParms.value = ''
    JMessage.success(result.message)
  } else {
    SelectMaterialQueryMehtods()
    MaterialDeletionMethodsParms.value = ''
    JMessage.error(result.message)
  }
}

const handleCloseMateriaLKlc = (_done?: () => void) => {
  ElMessageBox.confirm('确定要删除该数据吗')
    .then(async () => {
      MaterialDeletionMethods()
    })
    .catch(() => {})
}

// 入库明细新增

const currentRowList1 = (row: any) => {
  const { mtlNo } = row
  DetailsToBeStoredAreAddedMehtodsParms.value = mtlNo
  DetailsToBeStoredAreAddedMehtods()
}

const DetailsToBeStoredAreAddedMehtodsParms = ref('')

const DetailsToBeStoredAreAddedMehtods = async () => {
  const result = await DetailsToBeStoredAreAdded(DetailsToBeStoredAreAddedMehtodsParms.value)
  if (result.code === 200) {
    QueryDetailsToBeStoredMethods()
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

// 选择材料查询
const clearFormList = () => {
  formList2.value.forEach((item) => {
    if (item.type === 'input') {
      item.inputValue = ''
    }
    if (item.type === 'select') {
      item.selectValue = ''
    }
  })
}

const findData1 = (row: any) => {
  if (row === '置空') {
    clearFormList()
  }
  if (row === '删除') {
    if (MaterialDeletionMethodsParms.value === '') {
      JMessage.warning('请选择需要删除的数据')
    } else {
      handleCloseMateriaLKlc()
    }
  }
}

const Launchform2 = (row: any) => {
  SelectMaterialQueryMehtodsParmsList.value.mtlName = row[1].inputValue
  SelectMaterialQueryMehtodsParmsList.value.type = row[0].selectValue.split(' ')[0]
  SelectMaterialQueryMehtods()
}

const isLoading1 = ref(false)

const SelectMaterialQueryMehtodsTableDateList = ref<SelectMaterialQueryInterface>({
  dtos: []
})

const SelectMaterialQueryMehtodsParms = ref({
  pageNum: 1,
  pageSize: 40
})

const SelectMaterialQueryMehtodsParmsList = ref({
  mtlName: '',
  type: ''
})

const SelectMaterialQueryMehtods = async () => {
  isLoading1.value = true
  const result = await SelectMaterialQuery(
    SelectMaterialQueryMehtodsParmsList.value.mtlName,
    SelectMaterialQueryMehtodsParmsList.value.type,
    SelectMaterialQueryMehtodsParms.value
  )
  SelectMaterialQueryMehtodsTableDateList.value.dtos = result.dtos
  total.value = result.total!
  isLoading1.value = false
}

const total = ref(0)

const handleSizeChangeTk = (val: number) => {
  SelectMaterialQueryMehtodsParms.value.pageSize = val
  SelectMaterialQueryMehtods()
}

const handleCurrentChangeTk = (val: number) => {
  SelectMaterialQueryMehtodsParms.value.pageNum = val
  SelectMaterialQueryMehtods()
}

// 获取分类
const GainClassificationMehtods = async () => {
  let NewArray = []
  const result = await GainClassification()
  NewArray = result.reduce((arr: any, item: any) => {
    if (item.typeNo && item.typeName) {
      // 只添加非空的 typeName 和 typeNo
      arr.push(item.typeNo + ' ' + item.typeName)
    }
    return arr
  }, [])
  formList2.value[0].selectOptions = EvaluatesTheArrayReturnValue(NewArray)
  formList3.value[3].selectOptions = EvaluatesTheArrayReturnValue(NewArray)
}

// 厂商获取
const GainVendorMethods = async () => {
  let NewArray = []
  const result = await GainVendor()
  NewArray = result.reduce((arr: any, item: any) => {
    if (item.vendorNo && item.vendorName) {
      // 只添加非空的 typeName 和 typeNo
      arr.push(item.vendorNo + ' ' + item.vendorName)
    }
    return arr
  }, [])
  formList5.value[4].selectOptions = EvaluatesTheArrayReturnValue(NewArray)
  formList1.value[3].selectOptions = EvaluatesTheArrayReturnValue(NewArray)
}

// 部门获取
const EvaluatesTheArrayReturnValue = (ArrayList: any) => {
  return ArrayList.map((item: any, index: any) => {
    return {
      optionKey: index,
      optionValue: item,
      optionLabel: item
    }
  })
}

const GainDeptNmaeMethods = async () => {
  let NewArray = []
  const result = await GainDeptNmae()
  NewArray = result.reduce((arr: any, item: any) => {
    if (item.deptName && item.deptNo) {
      // 只添加非空的 typeName 和 typeNo
      arr.push(item.deptNo + ' ' + item.deptName)
    }
    return arr
  }, [])
  formList5.value[3].selectOptions = EvaluatesTheArrayReturnValue(NewArray)
}

// 入库明细查询
const Launchform3 = (row: any) => {
  QueryTheStorageDetailsMethodsParms.value.slipNo = row[0].inputValue
  QueryTheStorageDetailsMethodsParms.value.slipReason = row[1].selectValue
  QueryTheStorageDetailsMethodsParms.value.sendNo = row[2].inputValue
  QueryTheStorageDetailsMethodsParms.value.vendorNo = row[3].selectValue.split(' ')[0]
  QueryTheStorageDetailsMethodsParms.value.mtlName = row[4].inputValue
  QueryTheStorageDetailsMethodsParms.value.slipDateEnd = row[5].dateValue[1]
  QueryTheStorageDetailsMethodsParms.value.slipDateStart = row[5].dateValue[0]
  QueryTheStorageDetailsMethodsParms.value.sysDateEnd = row[6].dateValue[1]
  QueryTheStorageDetailsMethodsParms.value.sysDateStart = row[6].dateValue[0]
  QueryTheStorageDetailsMethods()
}

const QueryTheStorageDetailsMethodsParms = ref<any>({
  lotNo: '',
  mtlName: '',
  sendNo: '',
  slipDateEnd: '',
  slipDateStart: '',
  slipNo: '',
  slipReason: '',
  sysDateEnd: '',
  sysDateStart: '',
  vendorNo: '',
  pageSize: 40,
  pageNum: 1
})

const QueryTheStorageDetailsMethodsTableDateList = ref([])

const total1 = ref(0)

const handleSizeChangeTk1 = (val: number) => {
  QueryTheStorageDetailsMethodsParms.value.pageSize = val
  QueryTheStorageDetailsMethods()
}

const handleCurrentChangeTk1 = (val: number) => {
  QueryTheStorageDetailsMethodsParms.value.pageNum = val
  QueryTheStorageDetailsMethods()
}

const QueryTheStorageDetailsMethods = async () => {
  isLoading2.value = true
  const result = await QueryTheStorageDetails(QueryTheStorageDetailsMethodsParms.value)
  QueryTheStorageDetailsMethodsTableDateList.value = result.list
  total1.value = result.total
  isLoading2.value = false
}

// 待入库明细查询
const QueryDetailsToBeStoredMethodsTableDateList = ref<any>([])

const QueryDetailsToBeStoredMethods = async () => {
  isLoading.value = true
  const result = await QueryDetailsToBeStored()
  QueryDetailsToBeStoredMethodsTableDateList.value = result.map((item: any) => {
    item.change = 'Y'
    return item
  })
  isLoading.value = false
}

// 选择材料
const drawer3 = ref(false)

const findData = (count: any) => {
  if (count === '选择材料') {
    GainClassificationMehtods()
    SelectMaterialQueryMehtods()
    drawer3.value = true
  }
  if (count === '入库批处理') {
    if (
      StorageDetailsAddedMethodsParms.value.deptName === '' ||
      StorageDetailsAddedMethodsParms.value.vendorName === '' ||
      StorageDetailsAddedMethodsParms.value.slipReason === ''
    ) {
      JMessage.warning('数据输入不完整')
    } else {
      StorageDetailsAddedMethods()
    }
  }
  if (count === '打印') {
    console.log(slipNoList3.value)
    if (slipNoList3.value.length === 0) {
      JMessage.warning('请点击需要打印的数据')
    } else if (slipNoList3.value[0].slipNo === null) {
      JMessage.warning('请选择有出库单号的进行打印')
    } else {
      printQRCode()
    }
  }
}

const ObtainDataOnTheFirstScreen = () => {
  QueryDetailsToBeStoredMethods()

  QueryTheStorageDetailsMethods()

  GainDeptNmaeMethods()

  GainVendorMethods()
}

// 用户信息
const userInfo = ref()
const companyId = ref()
onMounted(() => {
  ObtainDataOnTheFirstScreen()

  let userInf = sessionStorage.getItem('userInfo')

  userInfo.value = JSON.parse(userInf!)

  companyId.value = sessionStorage.getItem('companyId')
})

// 表格数据
const tableHeader = ref([
  {
    label: '材料颜色',
    prop: 'mtlColor',
    change: true
  },
  {
    label: '材料名称',
    prop: 'mtlName',
    change: true
  },
  {
    label: '规格',
    prop: 'mtlSpec',
    change: true
  },
  {
    label: '单位',
    prop: 'mtlUnit',
    change: true
  },
  {
    label: '数量',
    prop: 'qty'
  },
  {
    label: '物料编码',
    prop: 'mtlNo',
    change: true
  },
  {
    label: '厂商代码',
    prop: 'vendorNo',
    change: true
  },
  {
    label: '订购单号',
    prop: 'purNo',
    change: true
  },
  {
    label: '厂商名称',
    prop: 'vendorName',
    change: true
  },
  {
    label: '备注',
    prop: 'remark'
  }
])

const tableHeader1 = ref([
  {
    label: '入库单号',
    prop: 'slipNo'
  },
  {
    label: '入库日期',
    prop: 'slipDate'
  },
  {
    label: '入库原因',
    prop: 'slipReason'
  },
  {
    label: '厂商',
    prop: 'vendorName'
  },
  {
    label: '材料颜色',
    prop: 'slipDate'
  },
  {
    label: '材料名称',
    prop: 'mtlName'
  },
  {
    label: '规格',
    prop: 'mtlSpec'
  },
  {
    label: '单位',
    prop: 'mtlUnit'
  },
  {
    label: '数量',
    prop: 'qty'
  },
  {
    label: '单价',
    prop: 'price'
  },
  {
    label: '金额',
    prop: 'amt'
  },

  {
    label: '送货日期',
    prop: 'sysDate'
  },
  {
    label: '物料编号',
    prop: 'mtlNo'
  },
  {
    label: '部门名称',
    prop: 'deptName'
  },
  {
    label: '送货单号',
    prop: 'sendNo'
  },
  {
    label: '厂商',
    prop: 'vendorNo'
  },
  {
    label: '仓管员',
    prop: 'sysUser'
  },
  {
    label: '备注',
    prop: 'remark'
  }
])

const tableHeader2 = ref([
  {
    label: '物料编码',
    prop: 'mtlNo'
  },
  {
    label: '分类名称',
    prop: 'typeName'
  },
  {
    label: '材料名称',
    prop: 'mtlName'
  },
  {
    label: '规格',
    prop: 'mtlSpec'
  },
  {
    label: '颜色',
    prop: 'mtlColor'
  },
  {
    label: '单位',
    prop: 'mtlUnit'
  }
])
</script>

<style lang="less" scoped>
h1 {
  font-size: 16px;
}
</style>
